package com.yinp.proapp.module.study.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.yinp.proapp.adapter.CommonAdapter;
import com.yinp.proapp.adapter.SingleViewHolder;
import com.yinp.proapp.base.activity.AppBaseActivity;
import com.yinp.proapp.databinding.ActivityStudySummarizeBinding;
import com.yinp.proapp.databinding.ItemStudySummarizeBinding;
import com.yinp.proapp.module.study.bean.StudySummarizeBean;
import com.yinp.proapp.utils.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yinp
 * @date 2021/8/17 16:53
 * @describe
 */

public class StudySummarizeActivity extends AppBaseActivity<ActivityStudySummarizeBinding> {
    private List<StudySummarizeBean> dataList = new ArrayList<>();
    private CommonAdapter<StudySummarizeBean> adapter;

    @Override
    protected void initViews() {
        setStatusBarHeight(StatusBarUtil.getStatusBarHeight(mContext));
        initClick(bd.header.headerBackImg);
        bd.header.headerCenterTitle.setText("学习类容总结");
        initRecycler();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == bd.header.headerBackImg) {
            finish();
        }
    }

    private void initRecycler() {
        dataList.add(new StudySummarizeBean("recyclerview的一些用法", "com.yinp.proapp.module.study.recycler.activity.RecyclerStudyActivity"));
        dataList.add(new StudySummarizeBean("弹窗的一些用法", "com.yinp.proapp.module.study.dialog.activity.DialogActivity"));
        dataList.add(new StudySummarizeBean("一些通用时间选择弹", "com.yinp.proapp.module.study.date.activity.SelectDateActivity"));
        dataList.add(new StudySummarizeBean("一些通用时间选择弹", "com.yinp.proapp.module.study.date.activity.SelectDateActivity"));
        adapter = new CommonAdapter<StudySummarizeBean>(mContext, dataList) {
            @Override
            protected SingleViewHolder setComViewHolder(View view, int viewType, ViewGroup parent) {
                return new SingleViewHolder(ItemStudySummarizeBinding.inflate(mInflater, parent, false));
            }

            @Override
            public void onBindItem(SingleViewHolder holder, int position, StudySummarizeBean item) {
                ItemStudySummarizeBinding binding = (ItemStudySummarizeBinding) holder.getBinding();
                binding.tvTitle.setText(item.getTitle());
            }
        };
        adapter.setOnItemClickListener((position, view) -> {
            if (!TextUtils.isEmpty(dataList.get(position).getUrl())) {
                Intent intent = new Intent();
                intent.setClassName(mContext, dataList.get(position).getUrl());
                goToActivity(intent);
            }
        });
        bd.rvList.setLayoutManager(new LinearLayoutManager(this));
        bd.rvList.setHasFixedSize(true);
        bd.rvList.setAdapter(adapter);
    }
}